﻿<%@ Page Title="" Language="C#" MasterPageFile="~/User/User.Master" AutoEventWireup="true" CodeBehind="SCJH_Edit.aspx.cs" Inherits="CoolERP_Web.User.SCJH_Edit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="../Scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="../Scripts/lhgdialog/lhgcore.min.js" type="text/javascript"></script>
<script src="../Scripts/lhgdialog/lhgdialog.js" type="text/javascript"></script>
<script type="text/javascript">
    var dg;
    function selGoods() {
        setHid();
        dg = new J.dialog({ id: 'select', title: '选择产品', page: 'SelectHTCP.aspx?ids=' + $("#hidSelIds").val(), iconTitle: false, cover: true, btnBar: false, rang: true, autoSize: true, width: 1200, height: 650 });
        dg.ShowDialog();
    }
    function selMore() {
        J('#GridView1 input[type=checkbox][id=chkSel]', dg.dgDoc).each(function () {
            if ($(this).attr("checked") == true) {
                var tr = $(this).closest("tr").clone();
                var count = $(tr).find("td").eq(9).text();
                $(tr).find("td").eq(9).html("<input type=text class=textbox id='txtCount' value='" + count + "' style='width:60px; text-align:center' onchange='setCount(this)' />");
                $(tr).find("input[type=checkbox]").attr("checked", false);
                $(tr).appendTo($("#tbList"));
            }
        });
        dg.cancel();
        sortTable('tbList', 3, 'numeric', 'asc');
        setTotal();
    }
    function setCount(obj) {
        var count = parseInt($(obj).val());
        if (count > 0) {
            var price = $(obj).parent().prev().text();
            if (isEmpty(price))
                price = 0;
            $(obj).parent().next().text((count * price).toFixed(2));
            setTotal();
        }
        else {
            $(obj).val("");
            alert('数量不能小于1');
        }
    }
    function doDelete() {
        var flag = false;
        $("#tbList input[type=checkbox][id=chkSel]").each(function () {
            if ($(this).attr("checked") == true) {
                flag = true;
                return;
            }
        });
        if (!flag) {
            alert("请从计划列表中选择产品");
            return;
        }
        $("#tbList input[type=checkbox][id=chkSel]").each(function () {
            if ($(this).attr("checked") == true)
                $(this).closest("tr").remove();
        });
        $("#tbList input[type=checkbox][id=chkAll]").attr("checked", false);
        sortTable('GridView1', 3, 'numeric', 'asc');
        setHid();
        setTotal();
    }
    function setHid() {
        var ids = "";
        $("#tbList input[type=checkbox][id=chkSel]").each(function () {
            ids += $(this).attr("value") + ",";
        });
        if (ids != "")
            ids = ids.substr(0, ids.length - 1);
        $("#hidSelIds").val(ids);
    }
    function setTotal() {
        var totalMoney = 0;
        $("#tbList tr").each(function (i) {
            if (i > 0) {
                var money = $(this).find("td").eq(10).text();
                totalMoney += parseFloat(money);
            }
        });
        $("#spanMoney").text(totalMoney.toFixed(2));
    }
    function doCreate() {
        setHid();
        if (isEmpty($("#hidSelIds").val())) {
            alert("请从合同列表中选择产品");
            return false;
        }
        if (isEmpty($("#txtS_Time").val())) {
            alert("请输入计划开始时间");
            return false;
        }
        if (isEmpty($("#txtE_Time").val())) {
            alert("请输入计划完成时间");
            return false;
        }
        return true;
    }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:HiddenField ID="hidSelIds" runat=server />
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td class=tbHead_L></td>
        <td class=tbHead_M><div><b><asp:literal ID="liTitle" runat=server>新增</asp:literal>生产计划</b></div></td>
        <td class=tbHead_R></td>
    </tr>
    <tr>
        <td class=tbBody_L></td>
        <td class=tbBody_M>
            <ul class=tags style="width:100%;">
                <li class=liTitle><div>计划列表</div></li>
                <li class=liRight><input type=button class=btn_s value="选择产品" onclick="selGoods()" style="cursor:pointer" />&nbsp;&nbsp;
                    <img src="../Images/Common/btn_del0.png" onclick="javascript:doDelete();" style="cursor:pointer" />&nbsp;&nbsp;
                    <font color=red>从计划列表中选择产品，点击确定后删除所选计划</font>&nbsp;&nbsp;
                    总计金额：¥<asp:Label ID="spanMoney" runat=server>0</asp:Label></li>
            </ul>
            <table id="tbList" class="grvCSS" cellspacing="0" rules="all" border="1" style="width:100%;border-collapse:collapse;">
		        <tr>
			        <th><label><input type="checkbox" id="chkAll" onclick="checkAll('tbList',this)" />全选</label></th>
                    <th>合同编号</th><th>客户简称</th><th>产品编号</th><th>产品名称</th><th>产品类型</th><th>产品规格</th>
                    <th>产品颜色</th><th>产品单价</th><th>生产数量</th><th>金额</th><th>出货时间</th>
		        </tr>
            <asp:Repeater ID="repMXList" runat="server">
            <ItemTemplate>
                <tr>
                    <td><input type=checkbox id="chkSel" name="chkSel" value='<%# Eval("ID") %>' /></td>
                    <td><%# Eval("HTBH")%></td><td><%# Eval("KHJC")%></td><td><%# Eval("CPBH")%></td>
                    <td><%# Eval("CPMC") %></td><td><%# Eval("CPLX")%></td><td><%# Eval("CPGG") %></td>
                    <td><%# Eval("CPYS") %></td><td><%# Eval("DJ") %></td><td><%# Eval("SL") %></td>
                    <td><%# (Convert.ToDecimal(Eval("DJ")) * Convert.ToDecimal(Eval("SL"))).ToString("C")%></td>
                    <td><%# Eval("CHSJ", "{0:yyyy-MM-dd}")%></td>
                </tr>
            </ItemTemplate>
            </asp:Repeater>
	        </table>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            <table class="grvCSS" cellspacing="0" border="1" style="width:100%;border-collapse:collapse;margin-top:10px">
		        <tr>
                    <td>计划开始时间：<asp:TextBox ID="txtS_Time" runat="server" CssClass="textbox Wdate" Width=90px onclick="WdatePicker({dateFmt: 'yyyy-MM-dd'});"/></td>
                    <td>计划完成时间：<asp:TextBox ID="txtE_Time" runat="server" CssClass="textbox Wdate" Width=90px onclick="WdatePicker({dateFmt: 'yyyy-MM-dd'});"/></td>
                    <td><asp:Button ID="btnCreate" CssClass="btn_s" runat="server" Text="生成计划" OnClick="btnCreate_Click" OnClientClick="return doCreate();" />&nbsp;&nbsp;
                        <a href="SCJH_Query.aspx"><img src="../Images/Common/btn_back0.png" border=0 /></a>&nbsp;&nbsp;
                        <asp:Label ID="labResult" runat="server" ForeColor=Red></asp:Label></td>
		        </tr>
	        </table></ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnCreate" EventName="Click" />
            </Triggers>
            </asp:UpdatePanel>
        </td>
        <td class=tbBody_R></td>
    </tr>
    <tr>
        <td class=tbFoot_L></td>
        <td class=tbFoot_M></td>
        <td class=tbFoot_R></td>
    </tr>
</table>
</asp:Content>
